//! @Author: DengLibin
//! @Date: Create in 2023-12-15 10:58:41
//! @Description:
//!

mod global;
mod ml;
use std::sync::Arc;

use global::GlobalResult;
use jieba_rs::Jieba;
use log::info;
use ml::beyes;
use rust_common::log_util;

/// @Author: DengLibin
/// @Date: Create in 2023-11-06 15:10:01
/// @Description: 日志初始化
pub fn init_log() -> GlobalResult<()> {
    let r = log_util::init_log(r"log4rs.yaml");
    global::check_result(r)
}

/// @Author: DengLibin
/// @Date: Create in 2023-12-19 14:47:55
/// @Description: 结巴分词器
pub fn init_jieba() -> GlobalResult<Jieba> {
    let jieba = Jieba::new();
    return Ok(jieba);
}

/// @Author: DengLibin
/// @Date: Create in 2023-11-06 15:10:09
/// @Description: 初始化
pub fn init() -> GlobalResult<(Jieba,)> {
    let _ = init_log()?;
    info!("日志初始化完成");
    let jieba = init_jieba()?;
    info!("结巴分词器初始化完成");
    return Ok((jieba,));
}

/// @Author: DengLibin
/// @Date: Create in 2023-12-15 11:10:32
/// @Description: 运行
pub async fn run(jieba: Arc<Jieba>) -> GlobalResult<()> {
    //knn算法
    //ml::knn::run().await

    //朴素贝叶斯算法
    beyes::run(jieba).await?;

    Ok(())
}

#[tokio::main]
async fn main() -> GlobalResult<()> {
    let r = init()?;

    let jieba = r.0;
    let jieba_r = Arc::new(jieba);

    run(jieba_r.clone()).await
}
